<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../layui/layui.js"></script>
    
    <script src="../js/jquery-1.8.0.min.js"></script>
    <script src="../js/ajax.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../css/shousuokuan.css">
</head>

<body>
    <script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-sm  layui-btn-danger" lay-filter="del" lay-event="del">删除</a>
</script>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <fieldset class="table-search-fieldset">
                <legend>搜索信息</legend>
                <div style="margin: 10px 10px 10px 10px">

                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">供货商编号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="supplierId" id="supplierId" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">供货商名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" id="name" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                        </div>
                        <div class="">
                            <label class="layui-form-label">时间：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="startDate" class="layui-input" id="startDate"
                                    placeholder="开始时间" autocomplete="off">
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" name="endDate" class="layui-input" id="endDate" placeholder="结束时间" autocomplete="off">
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">查询</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>

                        </div>


                    </form>


                </div>
            </fieldset>

        </div>
    </div>
    <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <!-- <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 新增供货商
                </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除选中
                </button> -->

                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="add">添加数据</button>

            </div>
        </script>

    <table id="demo" lay-filter="test"></table>
    </div>



    <script src="../js/host.js"></script>
    <script>
        $.ajaxSetup({
            headers: {
                "token": localStorage.getItem("token")
            }
        });
        layui.use(["table", 'form'], function () {
            var table = layui.table;
            var form = layui.form;
            var laydate = layui.laydate;
            //日期
            laydate.render({
                elem: '#startDate'
            });
            laydate.render({
                elem: '#endDate'
            });

            table.render({
                elem: '#demo'
                , url: host + '/supplierMvc/getListSupplier' //数据接口
                , page: true //开启分页
                , headers: {
                    "token": localStorage.getItem("token")
                }
                , toolbar: '#toolbarDemo'
                , loading: true
                , cols: [[ //表头
                    { type: 'numbers', title: '序号' }
                    , { field: 'id', title: 'ID', sort: true }
                    , { field: 'supplierId', title: '供货商编号' }
                    , { field: 'supplierName', title: '供货商名称', sort: true }
                    , { field: 'creation_date', title: '创建时间' }
                    , { fixed: 'right', width: 150, align: 'center', toolbar: '#barDemo' }
                ]]
            });

            // new ajax(host+":8080/WarehouseManageMaven_Web_exploded/getDepartment", "get", {}, "json", function (data) {
            //     $.each(data, function (index, item) {
            //         $("#departmentId").append("<option value='" + item.id + "'>" + item.departmentName + "</option>")
            //     })
            //     form.render("select")
            // });

            form.on("submit(add)", function (data) {
                layer.open({
                    type: 2,
                    title: "添加数据",
                    content: "table/SupplierAdd.html",
                    area: ['500px', '300px'],
                    end: function () {
                        table.reload('demo')
                    }
                })
                return false;
            })

            form.on('submit(formDemo)', function (data) {
                //当前容器的全部表单字段，名值对形式：{name: value}】
                table.reload('demo', {
                    where: data.field
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    } //设定异步数据接口的额外参数
                    //,height: 300
                });
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });


            table.on("tool(test)", function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        new ajax(host + "/supplierMvc/Sudelete", "get", { "id": data.id }, "json", function (data) {
                            obj.del();
                            layer.close(index);
                            table.reload('demo')
                        });
                    });
                } else if (obj.event === 'edit') {
                    layer.open({
                        type: 2,
                        title: '编辑数据',
                        shadeClose: true,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['500px', '300px'],
                        content: 'table/SupplierAdd.html',
                        success: function (layero, index) {
                            var body = layer.getChildFrame('body', index)
                            body.find("#suid").val(data.id)
                            body.find("#id").val(data.supplierId)
                            body.find("#name").val(data.supplierName)
                        },
                        end: function () {
                            table.reload('demo');
                        }
                    });
                }
            })
        })
    </script>
</body>

</html>